#include<vector>
#include<iostream>
#include<list>
using namespace std;
template<class T>
class Less
{
public:

	bool operator()(const T& x, const T& y)
	{
		return x < y;
	}
};
template<class T>
class greater
{
public:
	bool operator()(const T& x, const T& y)
	{
		return x > y;
	}
};
template<class T, class containter = vector<T>,class  compare=Less<int>>
class priority_queue
{
public:
	void push_back(const T& val)
	{
		con.push_back(val);
		sort_up(con.size() - 1);
	}
	void Pop()
	{

		swap(con[0], con[con.size() - 1]);
		con.pop_back();
		sort_down(0, con.size());
	}
	T& Top()
	{
		return con[0];
	}
	size_t size()
	{
		return con.size();
	}
	bool Empty()
	{
		return con.size() == 0;
	}
	void sort_up(size_t children)
	{
		compare sakura;
		size_t father = (children - 1) / 2;
		while (children > 0)
		{
			if (sakura(con[father],con[children]))
			{
				swap(con[children], con[father]);
				children = father;
				father = (children - 1) / 2;
			}
			else
				break;
		}
	}
	void sort_down(int father, size_t size)
	{
		compare sakura;
		int children = father * 2 + 1;
		while (children < size)
		{
			if (children + 1 < size && sakura(con[children], con[children+1]))
			{
				children++;
			}
			if (sakura(con[father], con[children]))
			{
				swap(con[children], con[father]);
				father = children;
				children = father * 2 + 1;
			}
			else
				break;
		}
	}
	

private:
	containter con;
};
